package com.cml.dm.admin.service.sql;

import com.cml.dm.admin.entity.DmExeLogger;
import com.cml.dm.admin.entity.DmMetadata;
import com.cml.dm.admin.service.BackupSqlGenerateService;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractBackupSqlGenerateService implements BackupSqlGenerateService {

    @Override
    public List<String> sqlGenerate(DmMetadata dmMetadata, DmExeLogger dmExeLogger, Object extParameter) {
        List<String> sqlList=doSqlGenerate(dmMetadata, dmExeLogger, extParameter);
        List<String> relSqlList= new ArrayList<>();
        sqlList.forEach(str->{
            String orderBy = "";
            if(StringUtils.isEmpty(dmMetadata.getSortField())){
                orderBy = " order by " + dmMetadata.getSortField();
            }
            relSqlList.add(str + orderBy);
        });
        return relSqlList;
    }

    public abstract List<String> doSqlGenerate(DmMetadata dmMetadata, DmExeLogger dmExeLogger, Object extParameter);
}